import os.path
import time

# 获取文件路径并写入文档
def get_filelist(dir):
    with open('rdtxt.txt', 'a+') as f:
        for home, dirs, files in os.walk(dir):
            for filename in files:
                fullname = os.path.join(home, filename)
                print(fullname)
                f.write(fullname + '\n')

def __get_all_files_in_local_dir(local_dir):
    # 用于保存所有文件的列表
    all_files = list()

    # 获取当前指定目录下的所有目录及文件，包含属性值
    files = os.listdir(local_dir)
    for x in files:
        # local_dir目录中每一个文件或目录的完整路径
        filename = os.path.join(local_dir, x)
        # 如果是目录，则递归处理该目录
        if os.path.isdir(filename):
            all_files.extend(__get_all_files_in_local_dir(filename))
        else:
            all_files.append(filename)
    return all_files

# 两种方式获取路径下的文件
if __name__ == "__main__":
    path = '/home/mp/workspace/python/somedir'
    # get_filelist(path)
    all_files = __get_all_files_in_local_dir(path)
    print(all_files)

